package com.cloud.flowable.service.impl;

import com.cloud.flowable.entity.WfForm;
import com.cloud.flowable.mapper.WfFormMapper;
import com.cloud.flowable.service.IWfFormService;
import com.cloud.utils.ExcelPoiUtils;
import com.cloud.utils.ServletUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WfFormServiceImpl implements IWfFormService {

    @Resource
    private WfFormMapper wfFormMapper;

    /**
     * 查询流程表单列表
     */
    @Override
    public List<WfForm> getFormList(WfForm wfForm) {
        return wfFormMapper.getFormList(wfForm);
    }

    /**
     * 新增流程表单
     */
    @Override
    public int saveWfForm(WfForm wfForm) {
        return wfFormMapper.insert(wfForm);
    }

    /**
     * 修改流程表单
     *
     * @param wfForm 流程表单
     * @return 结果
     */
    @Override
    public int updateForm(WfForm wfForm) {
        return wfFormMapper.updateById(wfForm);
    }

    /**
     * 查询流程表单
     *
     * @param formId 流程表单ID
     * @return 流程表单
     */
    @Override
    public WfForm getInfo(Long formId) {
        return wfFormMapper.selectById(formId);
    }

    /**
     * 批量删除流程表单
     *
     * @param ids 需要删除的流程表单ID
     * @return 结果
     */
    @Override
    public int removeIds(List<Long> ids) {
        return wfFormMapper.deleteBatchIds(ids);
    }

    /**
     * 流程表单导出
     */
    @Override
    public void export(WfForm wfForm) {
        List<WfForm> wfFormList = wfFormMapper.getFormList(wfForm);
        String titleName = "流程模型数据";
        ExcelPoiUtils.exportExcel(wfFormList, titleName, titleName,
                WfForm.class, titleName + ".xls", ServletUtils.getResponse());
    }

}
